
package jwww.util;

import java.io.*;

public class FileOperations
{
  public static byte[] read(File file)
  throws IOException
  {
    return read(file.getName());
  }

  public static byte[] read(String file)
  throws IOException
  {
    byte[] result;
    FileInputStream input = new FileInputStream(file);
    int size = new Long(file.length()).intValue();
    result  = new byte[size];
    int p        = 0;
    int maxchunk = 1024*1024;
    while (p < size)
    {
      int chunk  = Math.min(maxchunk, size-p);
      int actual = input.read(result, p, chunk);
      if (actual == -1)
        System.out.println("ERROR");
      p += actual;
    }
    input.close();
    return result;
  }
}
